/*
 * Copyright 2011 Daniel Krieg
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.code.csf.example;

import com.google.code.csf.ServiceAdapter;
import com.google.code.csf.ServiceProxy;
import com.google.code.csf.ServiceTemplate;

public class BusinessServiceProxy extends ServiceProxy<ComponentService> implements BusinessService {
    public BusinessServiceProxy(ServiceTemplate<ComponentService> serviceTemplate) {
        super(serviceTemplate);
    }

    public SomeResponse doSomething(final SomeRequest request) throws SomeException {
        return execute(SomeException.class, new ServiceAdapter<SomeResponse, ComponentService>() {
            public SomeResponse with(ComponentService service) throws Throwable {
                SomeComponentResponse response = service.doSomething(new SomeComponentRequest(request.getInput()));
                return new SomeResponse(response.getOutput());
            }
        });
    }

    public SomeOtherResponse doSomethingElse(final SomeOtherRequest request) throws SomeException {
        return execute(SomeException.class, new ServiceAdapter<SomeOtherResponse, ComponentService>() {
            public SomeOtherResponse with(ComponentService service) throws Throwable {
                SomeOtherComponentResponse response = service.doSomethingElse(new SomeOtherComponentRequest(request.getInput()));
                return new SomeOtherResponse(response.getOutput());
            }
        });
    }
}
